﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace SmokinAces.Object_Classes
{
    class GUI
    {
        Game_Engine parent;
        int MoneyTexture;
        int BarTexture;

        public GUI(Game_Engine parent)
        {
            this.parent = parent;
            MoneyTexture = parent.register_texture("gui\\Money.png");
            BarTexture = parent.register_texture("gui\\Bar.png");

            

        }


        #region Draw_Object Members

        public void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            float manaPercent = (float)parent.Hero.currentMana / parent.Hero.maxMana;
            float healthPercent = (float)parent.Hero.currentHealth / parent.Hero.maxHealth;
            VertexPositionColor[] ManaBar = new VertexPositionColor[4];
            ManaBar[0] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 6, 1.0f), Color.Maroon);
            ManaBar[1] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 25, 1.0f), Color.Maroon);
            ManaBar[2] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + (300 * healthPercent) + 6, parent.CurrentScreen.Max.Y - 6, 1.0f), Color.Maroon);
            ManaBar[3] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + (300 * healthPercent) + 6, parent.CurrentScreen.Max.Y - 25, 1.0f), Color.Maroon);
            VertexPositionColor[] HealthBar = new VertexPositionColor[4];
            HealthBar[0] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 30, 1.0f), Color.RoyalBlue);
            HealthBar[1] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 49, 1.0f), Color.RoyalBlue);
            HealthBar[2] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + (300 * manaPercent)+6, parent.CurrentScreen.Max.Y - 30, 1.0f), Color.RoyalBlue);
            HealthBar[3] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + (300 * manaPercent) + 6, parent.CurrentScreen.Max.Y - 49, 1.0f), Color.RoyalBlue);
            VertexPositionColor[] BackManaBar = new VertexPositionColor[4];
            BackManaBar[0] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 6, 1.0f), Color.Black);
            BackManaBar[1] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 25, 1.0f), Color.Black);
            BackManaBar[2] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 306, parent.CurrentScreen.Max.Y - 6, 1.0f), Color.Black);
            BackManaBar[3] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 306, parent.CurrentScreen.Max.Y - 25, 1.0f), Color.Black);
            VertexPositionColor[] BackHealthBar = new VertexPositionColor[4];
            BackHealthBar[0] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 30, 1.0f), Color.Black);
            BackHealthBar[1] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 6, parent.CurrentScreen.Max.Y - 49, 1.0f), Color.Black);
            BackHealthBar[2] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 306, parent.CurrentScreen.Max.Y - 30, 1.0f), Color.Black);
            BackHealthBar[3] = new VertexPositionColor(new Vector3(parent.CurrentScreen.Min.X + 306, parent.CurrentScreen.Max.Y - 49, 1.0f), Color.Black);

            parent.GraphicsDevice.VertexDeclaration = ((Game_Engine)parent).VertexPosColor;
            //---------Begin the drawing passes
            parent.LineEffect.Begin();
            foreach (EffectPass pass in parent.LineEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                parent.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, BackManaBar, 0, 2);
                parent.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, BackHealthBar, 0, 2);
                    parent.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, ManaBar, 0, 2);
                    parent.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, HealthBar, 0, 2);
                pass.End();
            }
            parent.LineEffect.End();
            
            //Game_Effect.Projection = Matrix.CreateOrthographicOffCenter(0, parent.GraphicsDevice.Viewport.Width, 0, parent.GraphicsDevice.Viewport.Height, 0.0f, 1024.0f);;
            Rectangle MoneyRectangle = new Rectangle(parent.GraphicsDevice.Viewport.Width - 25, parent.GraphicsDevice.Viewport.Height - 25, 25, 25);
            Rectangle HealthRectangle = new Rectangle(6, 6, 300, 20);
            Rectangle ManaRectangle = new Rectangle(6, 30, 300, 20);
            //Health Calc
            Vector2 HealthTextLocation = new Vector2(152,17);
            String HealthString = "Health: " + ((int)(((float)parent.Hero.currentHealth / parent.Hero.maxHealth) * 100)) + "%";
            HealthTextLocation -= parent.GUIFont12.MeasureString(HealthString) / 2;
            //Mana Calc
            Vector2 ManaTextLocation = new Vector2(152,40);
            String ManaString = "Mana: " + ((int)(((float)parent.Hero.currentMana/parent.Hero.maxMana)*100)) + "%";
            ManaTextLocation -= parent.GUIFont12.MeasureString(ManaString) / 2;
            //Money Calc
            Vector2 MoneyTextLocation = new Vector2(parent.GraphicsDevice.Viewport.Width - 27, parent.GraphicsDevice.Viewport.Height +4);
            String MoneyString = Convert.ToString(parent.Hero.currentMoney);
            MoneyTextLocation -= parent.GUIFont16.MeasureString(MoneyString);
            parent.spriteBatch.Begin();
                parent.spriteBatch.Draw(parent.Texture_List[MoneyTexture], MoneyRectangle, Color.White);
                parent.spriteBatch.Draw(parent.Texture_List[BarTexture], HealthRectangle, Color.White);
                parent.spriteBatch.Draw(parent.Texture_List[BarTexture], ManaRectangle, Color.White);
                parent.spriteBatch.DrawString(parent.GUIFont12, HealthString, HealthTextLocation, Color.White);
                parent.spriteBatch.DrawString(parent.GUIFont12, ManaString, ManaTextLocation, Color.White);
                parent.spriteBatch.DrawString(parent.GUIFont16, MoneyString, MoneyTextLocation, Color.White);
            parent.spriteBatch.End();
            parent.GraphicsDevice.RenderState.DepthBufferEnable = true;
        }


        #endregion
    }
}
